home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / HYP / C-D / DeveloperStax.cpt / Developer Stack 1.0 / card_9721.txt < prev    next >
Text File  |  1989-02-26  |  7KB  |  224 lines

  1. -- card: 9721 from stack: in.0
  2. -- bmap block id: 0
  3. -- flags: 4000
  4. -- background id: 3837
  5. -- name: NewMenu
  6. ----- HyperTalk script -----
  7. on opencard  -- create the menus
  8.   --  keep the "handles" to the menus in these globals
  9.   global menu1, menu2
  10.   show menubar
  11.   put NewMenu("Beep","Once","Twice","(-","Boing/9") into menu1
  12.   if menu1 is 0 then answer("Unable to make menu 'BEEP'") with "Drat"
  13.   put NewMenu("Visual","Effect 1") into menu2
  14.   if menu2 is 0 then answer("Unable to make menu 'Visual'") with "Drat"
  15. end opencard
  16.  
  17. on closecard  --  delete the menus we've created using
  18.   --the globals saved in openStack
  19.   global menu1, menu2
  20.   put DeleteMenu(menu1) into menu1  --  clearing global for safety
  21.   put DeleteMenu(menu2) into menu2
  22.   hide menubar
  23. end closecard
  24.  
  25.  
  26. on idle  --  call ShowMenu every so often just in case our menus vanished
  27.   global menu1, menu2, lastTick
  28.   if (the ticks-lastTick)>120 then  --  gives better
  29.     -- performance than on every iteration
  30.     put the ticks into lastTick
  31.     ShowMenu(menu1)
  32.     ShowMenu(menu2)
  33.   end if
  34.   pass idle
  35. end idle
  36.  
  37.  
  38. on doMenu which  --  get our menu items from doMenu
  39.   -- before HyperCard does...
  40.   global menu1, menu2  -- for CheckMenu and
  41.   -- EnableMenu below
  42.   if which is "Once" then
  43.     beep 1
  44.     CheckMenu menu1,1,true
  45.   else if which is "Twice" then
  46.     beep 1
  47.     wait 4
  48.     beep 1
  49.     CheckMenu menu1,2,true
  50.   else if which is "Boing" then
  51.     play "Boing"
  52.     CheckMenu menu1,4,true
  53.   else if which is "Effect 1" then
  54.     push card
  55.     visual effect dissolve to black
  56.     pop card
  57.     EnableMenu menu2,1,false
  58.   else pass doMenu  --  Remember to pass on menu commands you don't trap!
  59. end doMenu
  60.  
  61.  
  62.  
  63. -- part 1 (button)
  64. -- low flags: 00
  65. -- high flags: A003
  66. -- rect: left=82 top=302 right=324 bottom=182
  67. -- title width / last selected line: 0
  68. -- icon id / first selected line: 0 / 0
  69. -- text alignment: 1
  70. -- font id: 0
  71. -- text size: 12
  72. -- style flags: 0
  73. -- line height: 16
  74. -- part name: Install
  75. ----- HyperTalk script -----
  76. on mouseUp
  77.   if the optionkey is down then
  78.     pass mouseup
  79.   end if
  80.  
  81.   put (long name of this stack) into sourceStack
  82.   delete first word of sourceStack
  83.   delete first character of sourceStack
  84.   delete last character of sourceStack
  85.   put "Select a stack to copy this resource into."
  86.   put filename("STAK") into fname
  87.   if fname is empty then
  88.     hide message window
  89.     exit mouseup
  90.   end if
  91.   if sourcestack=fname then
  92.     beep
  93.     Answer "Get real.  You can't install it in this stack"
  94.     hide message window
  95.     exit mouseup
  96.   end if
  97.  
  98.   --
  99.   ModResCopy sourceStack,fname,"XFCN","NewMenu"
  100.   --
  101.   get the result
  102.   if first char of it is "E" then
  103.     put it into the message box
  104.     beep
  105.     answer "Attempt to install resource has failed."
  106.   else
  107.     beep
  108.     answer "Resource installation successful"
  109.   end if
  110.   hide message window
  111. end mouseUp
  112.  
  113.  
  114.  
  115. -- part contents for background part 5
  116. ----- text -----
  117. NewMenu
  118.  
  119. -- part contents for background part 10
  120. ----- text -----
  121. 3
  122.  
  123. -- part contents for background part 6
  124. ----- text -----
  125.  
  126. NewMenu allows you to add your own menus to a HyperCard stack.  You may have up to eight menus with up to 15 items per menu.  
  127.  
  128. When you change userLevels, or select paint tools, or do anything to cause HyperCard to change the menu bar--your new menu will be erased from the menu bar.  It is NOT gone from memory, just from the menu bar.  To have it replaced automatically do the "on idle" routine shown below.  This will make sure your menu is showing whenever you are in browse mode 
  129. (on idle is not called when you're in button, field, or paint tools mode).
  130.  
  131. All this would generally be done in a stack's script as follows:
  132.  
  133. on openStack  -- create the menus
  134.   --  keep the "handles" to the menus in these globals
  135.   global menu1, menu2  
  136.   put NewMenu("Beep","Once","Twice","(-","Boing/9")   
  137.          into menu1
  138.   if menu1 is 0 then answer("Unable to make menu 'BEEP'")           
  139.         with "Drat"
  140.   put NewMenu("Visual","Effect 1") into menu2
  141.   if menu2 is 0 then answer("Unable to make menu 
  142.         'Visual'") with "Drat"
  143. end openStack
  144.  
  145.  
  146. on closeStack  --  delete the menus we've created using 
  147.                        --the globals saved in openStack
  148.   global menu1, menu2
  149.   put DeleteMenu(menu1) into menu1  --  clearing global
  150.                                                          --  for safety
  151.   put DeleteMenu(menu2) into menu2
  152. end closeStack
  153.  
  154.  
  155. on idle  --  call ShowMenu every so often just in case 
  156.             --  our menus vanished
  157.   global menu1, menu2, lastTick
  158.   if (the ticks-lastTick)>120 then  --  gives better
  159.                            -- performance than on every iteration
  160.     put the ticks into lastTick
  161.     ShowMenu(menu1)
  162.     ShowMenu(menu2)
  163.   end if
  164.   pass idle
  165. end idle
  166.  
  167.  
  168. on doMenu which  --  get our menu items from doMenu 
  169.                            -- before HyperCard does...
  170.   global menu1, menu2  -- for CheckMenu and 
  171.                                    -- EnableMenu below
  172.   if which is "Once" then
  173.     beep 1
  174.     CheckMenu menu1,1,true
  175.   else if which is "Twice" then
  176.     beep 1
  177.     wait 4
  178.     beep 1
  179.     CheckMenu menu1,2,true 
  180.   else if which is "Boing" then
  181.     play "Boing"
  182.     CheckMenu menu1,4,true 
  183.   else if which is "Effect 1" then
  184.     push card
  185.     visual effect dissolve to black
  186.     pop card
  187.     EnableMenu menu2,1,false 
  188.     else pass doMenu  --  Remember to pass on menu 
  189.                                 --  commands you don't trap!
  190. end doMenu
  191.  
  192.  
  193. Notice that if you want the menu to appear for all cards in the stack, you would place the NewMenu function in the stack's script and install it "on openStack" and remove it 
  194. "on closeStack".  If you wanted a menu to appear only for a certain background, the commands would be in that background's script and done "on openBackground" and "on closeBackground".  And the commands to make a menu to appear only on a certain card would be done in that card's script "on openCard"/"on closeCard".
  195.  
  196. •••
  197.  
  198. All the credit, (even the descriptions above) go to the creator of this ingenious XFCN:
  199.  
  200. Nine to Five Software Company
  201. P.O. Box 915
  202. Greenwood, IN  46142
  203. (317) 887-2154
  204. & Michael Long
  205.  
  206. See also CheckMenu*, EnableMenu*, DeleteMenu*, and ChangeMenu*.
  207.  
  208.  
  209. -- part contents for background part 7
  210. ----- text -----
  211. Syntax:
  212.  
  213. put NewMenu("Title","Item1","Item2",...,"Item n") into yourName
  214.  
  215.  
  216. "Title" is the name that will be put into the menubar.
  217.  
  218. "Item1" through "Item n" are the names of the items in the pull down part of the menu.
  219.  
  220. Add an item like "(-" to insert a divider line between menu options.  You may also end items with a slash letter (as is "An item/I") to add command keys.
  221.  
  222.  
  223. The number the NewMenu function returns is a reference number to the menu you just installed.  You MUST have this number to delete or make changes to the menu later on!  
  224.